import React from "react"
import { isString, isNumber } from "./is"
const isSingleNode = (child) => {
    return isNumber(child) || isString(child)
}
export const mergedToString = (children) => {
    const mergedResult = [""]
    React.Children.forEach(children, child => {
        const prevIndex = mergedResult.length - 1
        const prevChild = mergedResult[prevIndex]
        if (isSingleNode(child) && isSingleNode(prevChild)) {
            mergedResult[prevIndex] = `${prevChild}${child}`
        } else if (child?.props?.children) {
            mergedResult.push(mergedToString(child.props.children))
        }
    })
    return mergedResult.join("")
}